<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>坤哥图书</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #e9ecef;
            margin: 0;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            min-height: 100vh;
        }

        .container {
            background-color: #ffffff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 1200px;
            margin-bottom: 20px;
        }

        h1 {
            color: #343a40;
            text-align: center;
            margin-bottom: 20px;
        }

        table {
            width: 100%;
            margin: 20px 0;
            border-collapse: collapse;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
            background-color: #fff;
            border-radius: 8px;
            overflow: hidden;
        }

        th, td {
            padding: 12px 15px;
            border-bottom: 1px solid #dee2e6;
            text-align: left;
        }

        th {
            background-color: #007bff;
            color: white;
            font-weight: bold;
        }

        tr:nth-child(even) {
            background-color: #f8f9fa;
        }

        tr:hover {
            background-color: #e9ecef;
        }

        .button-container {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-bottom: 20px;
            flex-wrap: wrap;
        }

        .button {
            background-color: #28a745;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
            font-size: 1rem;
            transition: background-color 0.3s ease;
        }

        .button:hover {
            background-color: #218838;
        }

        .button.edit {
            background-color: #ffc107;
        }

        .button.edit:hover {
            background-color: #e0a800;
        }

        .button.delete {
            background-color: #dc3545;
        }

        .button.delete:hover {
            background-color: #c82333;
        }

        .alert {
            padding: 15px;
            margin-bottom: 20px;
            border: 1px solid transparent;
            border-radius: 4px;
        }

        .alert-danger {
            color: #721c24;
            background-color: #f8d7da;
            border-color: #f5c6cb;
        }

        input[type="text"] {
            padding: 10px;
            border: 1px solid #ced4da;
            border-radius: 4px;
            font-size: 1rem;
            flex-grow: 1; /* Allow input to grow */
            min-width: 150px; /* Minimum width for responsiveness */
        }

.header-container {
            display: flex;
            justify-content: space-between; /* Distribute items */
            align-items: center;
            padding: 10px 20px;
            background-color: #f8f8f8;
            border-bottom: 1px solid #eee;
            flex-wrap: wrap;
        }

.search-and-add-container {
            display: flex;
            gap: 10px;
            align-items: center;
            flex-wrap: wrap;
            margin: 0 auto; /* Center the container itself */
        }

        .search-form {
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .add-button {
            margin-left: 10px;
        }

        .logout-form {
            /* No specific margin-left needed here, as space-between will handle it */
        }

        @media (max-width: 768px) {
            .container {
                padding: 20px;
            }

            table, thead, tbody, th, td, tr {
                display: block;
            }

            thead tr {
                position: absolute;
                top: -9999px;
                left: -9999px;
            }

            tr {
                border: 1px solid #ccc;
                margin-bottom: 10px;
                border-radius: 8px;
                overflow: hidden;
            }

            td {
                border: none;
                border-bottom: 1px solid #eee;
                position: relative;
                padding-left: 50%;
                text-align: right;
            }

            td:before {
                position: absolute;
                top: 6px;
                left: 6px;
                width: 45%;
                padding-right: 10px;
                white-space: nowrap;
                content: attr(data-label);
                font-weight: bold;
                text-align: left;
            }

            td:last-child {
                border-bottom: 0;
            }

            td:nth-of-type(1):before { content: "ID"; }
            td:nth-of-type(2):before { content: "书名"; }
            td:nth-of-type(3):before { content: "作者"; }
            td:nth-of-type(4):before { content: "ISBN"; }
            td:nth-of-type(5):before { content: "价格"; }
            td:nth-of-type(6):before { content: "书籍位置"; }
            td:nth-of-type(7):before { content: "操作"; }

            .button-container {
                flex-direction: column;
                align-items: center;
                width: 100%;
            }

            .button {
                width: 100%;
                text-align: center;
            }

            input[type="text"] {
                width: 100%;
                margin-bottom: 10px;
            }

            .search-and-add-container {
                flex-direction: column;
                width: 100%;
            }

            .search-form {
                width: 100%;
                flex-direction: column;
            }

            .add-button {
                margin-left: 0;
                margin-top: 10px;
            }

            .logout-form {
                margin-left: 0;
                margin-top: 10px;
                width: 100%;
                text-align: center;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header-container">
            <h1>坤哥图书</h1>
            <div class="search-and-add-container">
                <form th:action="@{/books}" method="get" class="search-form">
                    <input type="text" name="keyword" placeholder="搜索书名、作者或ISBN">
                    <button type="submit" class="button">搜索</button>
                </form>
                <a href="books/new" class="button add-button">添加新书</a>
            </div>
            <form th:action="@{/logout}" method="post" class="logout-form">
                <button type="submit" class="button">退出登录</button>
            </form>
        </div>

    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>书名</th>
                <th>作者</th>
                <th>ISBN</th>
                <th>价格</th>
                <th>书籍位置</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <tr th:each="book : ${books}">
                <td th:text="${book.id}"></td>
                <td th:text="${book.title}"></td>
                <td th:text="${book.author}"></td>
                <td th:text="${book.isbn}"></td>
                <td th:text="${book.price}"></td>
                <td th:text="${book.location}" style="text-align: center;"></td>
                <td>
                    <a th:href="@{/books/edit/{id}(id=${book.id}, keyword=${param.keyword})}" class="button edit">编辑</a>
                    <a th:href="@{/books/delete/{id}(id=${book.id}, keyword=${param.keyword})}" class="button delete">删除</a>
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>